package com.pignest.hotel.module.user.ui;

import java.util.List;

import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.EventListener;
import org.zkoss.zk.ui.event.Events;
import org.zkoss.zul.Listbox;
import org.zkoss.zul.Listcell;
import org.zkoss.zul.Listhead;
import org.zkoss.zul.Listitem;
import org.zkoss.zul.Textbox;


import com.pignest.hotel.beans.Member;
import com.pignest.hotel.service.MemberService;
import com.pignest.hotel.spring.Services;

public class SelectMemberListBox extends Listbox {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1894246433773562058L;
	public SelectMemberListBox(){
		memberService=Services.getMemberService();
	}
	public void onCreate() {
		this.setHead();
		query();
	}
	
    private Textbox nameField;//会员姓名
    
    private String name;

	
	private Textbox mobileField;//手机
	
	private String mobile;

	
	private Textbox mailField;//邮件
	
	private String mail;
	
	private Textbox cardNoField;//卡号
	
	private String cardNo;
	
	public Member member;
	
	private MemberService memberService;

	public Textbox getNameField() {
		return nameField;
	}

	public void setNameField(Textbox nameField) {
		this.nameField = nameField;
	}

	public Textbox getMobileField() {
		return mobileField;
	}

	public void setMobileField(Textbox mobileField) {
		String levelId=(String)mobileField.getValue();
		this.mobile=levelId;
	    this.query();
	}

	public Textbox getMailField() {
		return mailField;
	}

	public void setMailField(Textbox mailField) {
		this.mailField = mailField;
	}

	public Textbox getCardNoField() {
		return cardNoField;
	}

	public void setCardNoField(Textbox cardNoField) {
		this.cardNoField = cardNoField;
	}
	
	public Member getMember() {
		//System.out.println("回调!!!!!");
		return member;
	}
	public void setMember(Member member) {
		//System.out.println("设置！！！！");
		if(member!=null)
		this.member = member;
		else
		this.member=null;
	}
	public void query(){
		
		   //this.setHead();
		this.getItems().clear();
		    System.out.println(this.mobile);
			StringBuffer hql=new StringBuffer();
			hql.append(" from Member b where 1=1 ");
			if(this.mobile!=null&&!this.mobile.equals(""))
		    hql.append(" and b.mobile like '%"+this.mobile+"%'");
			List<Member> memberList =memberService.find(hql.toString());
			for(int i=0;i<memberList.size();i++){
				final Member member = memberList.get(i);
				Listitem listitem = new Listitem();
				
				listitem.setValue(member.getId());
				listitem.setParent(this);
				listitem.appendChild(new Listcell(Integer.toString(i+1)));
				listitem.appendChild(new Listcell(member.getName()));
				listitem.appendChild(new Listcell(member.getType()));
				listitem.appendChild(new Listcell(member.getSex()));
				listitem.appendChild(new Listcell(member.getMobile()));
				listitem.appendChild(new Listcell(member.getCertificatType()));
				listitem.appendChild(new Listcell(member.getCertificateNo()));
				listitem.appendChild(new Listcell(member.getMail()));
				listitem.appendChild(new Listcell(member.getRegisterMode()));
				listitem.appendChild(new Listcell(member.getSendCardWay()));
				listitem.appendChild(new Listcell(member.getNation()));
				listitem.appendChild(new Listcell(member.getProvince()));
				listitem.appendChild(new Listcell(member.getCardNo()));
				listitem.appendChild(new Listcell(member.getMail()));
				listitem.addEventListener(Events.ON_CLICK,  new EventListener(){
					public void onEvent(Event event) throws Exception {   
						
						setMember(member);
					}
				});
			
			}
	}
	public void setHead(){
		ModelListHead modelhead = new ModelListHead();
		Listhead head = modelhead.memberListHead(this);
	}


}
